﻿namespace JinShun.OA.UI
{
    public class RequesResult
    {
        private int code { get; set; }
        private string message { get; set; }
        private Dictionary<string, object> data { get; set; } = new Dictionary<string, object>();

        public int GetRequesCode()
        {
            return code;
        }
        public T GetData<T>()
        {
            string result = Newtonsoft.Json.JsonConvert.SerializeObject(data.Values);
            if (this.code == 0)
            {
                result = result.Replace("\\", string.Empty);
                result = result.Replace("[\"", string.Empty);
                result = result.Replace("\"]", string.Empty);
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(result);
        }
        public static RequesResult ok()
        {
            RequesResult r = new RequesResult();
            r.code = 0;
            r.message = "成功";
            return r;
        }
        public static RequesResult error()
        {
            RequesResult r = new RequesResult();
            r.code = -1;
            r.message = "失败";
            return r;
        }
        public RequesResult putdata(string key, object value)
        {
            this.data.Add(key, value);
            return this;
        }
    }
}
